package xyz.bali16.module.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.bali16.module.article.entity.ArticleCategory;
import xyz.bali16.module.article.mapper.ArticleCategoryMapper;
import xyz.bali16.module.article.mapper.CategoryMapper;
import xyz.bali16.module.article.service.ArticleCategoryService;

import java.util.List;
import java.util.Map;


@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory> implements ArticleCategoryService {

    @Autowired
    private ArticleCategoryMapper articleCategoryMapper;

    @Override
    public void addArticleCategory(String articleId, String categoryId) {
        ArticleCategory articleCategory = new ArticleCategory();
        articleCategory.setArticleId(articleId);
        articleCategory.setCategoryId(categoryId);
        save(articleCategory);
    }

    @Override
    public ArticleCategory getByArticleId(String articleId) {
        Wrapper<ArticleCategory> wrapper = Wrappers.<ArticleCategory>lambdaQuery()
                .eq(ArticleCategory::getArticleId, articleId);
        return getOne(wrapper);
    }

    @Override
    public void deleteByArticleId(String articleId) {
        Wrapper<ArticleCategory> wrapper = Wrappers.<ArticleCategory>lambdaQuery()
                .eq(ArticleCategory::getArticleId, articleId);
        remove(wrapper);
    }
}

